/******************************************************************************
** 
** File name:	UTEST_13.c
**	
** Description: RTOS Unit Tests. Basic Task/ISR Management Tests. 
**				- Single level interrupt processing. 
**				- Single interrupt source.
**				- No nested interrupts.
**
** RTOS API functions to be tested:
**
**	RTOS_ISR_SuspendTask()
**	RTOS_ISR_ResumeTask()
**
******************************************************************************/
#include <avr/io.h>
#include <avr/interrupt.h>
#include "rtos.h"
#include "utest.h"

/******************************************************************************
**	RTOS DECLARARTION SECTION
**
**  Standard config for RTOS MESSAGE QUEUE Services Unit Tests should look
**	as follows:
**
**	Timer interrupt #1:			Not configured
**	Timer interrupt #2:			USER_TimerHandler (defined by USER)
**
**	Events:						n/a
**	Messages:					n/a
**	Queues:						n/a
**	Timers:						n/a
**	
**	Three tasks:				tsk1,		tsk2,		tsk3 
**  Three priorities:			1 (high)	2 (middle)	3 (low)
**  Stack size:					20			20			20
**
**  Notes:	
**
******************************************************************************/

RTOS_DECLARE_ISR(SYSTEM_TIMER_VECTOR,DUMMY_TimerHandler);
RTOS_DECLARE_ISR(USER_TIMER_VECTOR,USER_TimerHandler);

RTOS_DECLARE_TASK(tsk1, 20, 1);
RTOS_DECLARE_TASK(tsk2, 20, 2);
RTOS_DECLARE_TASK(tsk3, 20, 3);

static volatile uint8_t TimerCounter = 0;

/*
** RTOS main function
*/
int main(void)
{
    rtos_initialize_os(0);

	// obsolete UTST_HwInit();
	
	// obsolete usr_tick_init(1000);		// 1KHz (1,000 mSec) timer

    rtos_task_start(RTOS_GetTCB(tsk1));
    rtos_task_start(RTOS_GetTCB(tsk2));
    rtos_task_start(RTOS_GetTCB(tsk3));

	rtos_start_os();						// Start OS from this point
	
    while(1);
}

/*
** Dummy Timer Handler
*/
RTOS_ISR_FUNC(DUMMY_TimerHandler)
{
}

/*
** User' Timer Handler
*/
RTOS_ISR_FUNC(USER_TimerHandler)
{
	RTOS_ISR_TaskSuspend(&tsk1PID);
	RTOS_ISR_TaskSuspend(&tsk2PID);
}

/*
** RTOS Task #1
*/
RTOS_TASK_FUNC(tsk1)
{
	UTST_FillRegisters();
	while(1)
	{
	}
}

/*
** RTOS Task #2 
*/
RTOS_TASK_FUNC(tsk2)
{
	while(1)
	{
		rtos_task_resume(&tsk1PID);
	}
}

/*
** RTOS Task #3 
*/
RTOS_TASK_FUNC(tsk3)
{
	while(1)
	{
		rtos_task_resume(&tsk2PID);		
	}
}

